package org.setaria.utils
{
	import flash.display.DisplayObject;
	import flash.events.Event;
	import flash.utils.Dictionary;
	
	import mx.core.FlexGlobals;
	import mx.core.IFlexDisplayObject;
	import mx.core.IFlexModuleFactory;
	import mx.effects.Effect;
	import mx.effects.Parallel;
	import mx.events.EffectEvent;
	import mx.events.FlexEvent;
	import mx.managers.PopUpManager;
	
	import org.setaria.effect.SetariaEffectPool;
	
	import spark.components.Application;
	import spark.effects.Fade;

	/**
	 * 弹出窗口和移除弹出窗口
	 * @author Pu Kevin
	 * @Date 2010-12-7
	 * */
	public class SetariaPopUpManager
	{
		
		
		public function SetariaPopUpManager()
		{
			super();
			
		}
		
		/**
		 * 弹出窗口并居中，播放默认效果
		 * 
		 * */
		public static function centerPopup(window:IFlexDisplayObject,parent:DisplayObject,modal:Boolean = false, childList:String=null, moduleFactory:IFlexModuleFactory=null):void{
			var effect:Effect = SetariaEffectPool.getEffect(SetariaEffectPool.defaultPopUpEffect);
			effect.target = window;
			window.addEventListener(Event.ADDED, function playeffect():void{
				effect.end();
				effect.play();
				window.removeEventListener(Event.ADDED,playeffect);
			});
			PopUpManager.addPopUp(window,parent,modal,childList,moduleFactory);
			window.x = ((FlexGlobals.topLevelApplication as Application).width - window.width) / 2;
			window.y = ((FlexGlobals.topLevelApplication as Application).height - window.height) / 2;
		}
		/**
		 * 弹出窗口，在X轴居中，距离顶部10像素，一般用于弹出比较大的窗口，播放默认效果
		 * 
		 * */
		public static function popup(window:IFlexDisplayObject,parent:DisplayObject,modal:Boolean = false, childList:String=null, moduleFactory:IFlexModuleFactory=null):void{
			var effect:Effect = SetariaEffectPool.getEffect(SetariaEffectPool.defaultPopUpEffect);
			effect.target = window;
			window.addEventListener(Event.ADDED, function playeffect():void{
				effect.end();
				effect.play();
				window.removeEventListener(Event.ADDED,playeffect);
			});
			PopUpManager.addPopUp(window,parent,modal,childList,moduleFactory);
			window.x = ((FlexGlobals.topLevelApplication as Application).width - window.width) / 2;
			window.y = 10;
		}
		/**
		 * 移除窗口，播放默认效果
		 * */
		public static function remove(window:IFlexDisplayObject):void{
			var effect:Effect = SetariaEffectPool.getEffect(SetariaEffectPool.defaultRemoveEffect);
			effect.target = window;
			effect.addEventListener(EffectEvent.EFFECT_END,function removewindow():void{
				PopUpManager.removePopUp(window);
				effect.removeEventListener(EffectEvent.EFFECT_END,removewindow);
				window = null;
			});
			effect.end();
			effect.play();
		}
	}
	
}